var http = require('http');
var fs = require('fs');
var ws = require('socket.io');

var server = http.createServer(function (req, res, next) {
  var html = fs.readFileSync('./client.html');
  res.setHeader('Content-type', 'text/html');
  res.end(html);
});

// 新建io实例 挂载到web服务器中
var io = ws(server);
// 监听客户端连接
io.on('connection', function (socket) {
  console.log('用户已经连接到聊天室');
  socket.on('message', function (mes) {
    console.log(mes);
    io.emit('message', mes);
  });
});

server.listen(3000);
console.log('服务开启: 3000');